/*
 * 上海远境文化传媒有限公司 版权所有
 */
package helper;

import play.Logger;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 全局配置的key定义.
 *
 * 这里定义的配置项目，可以通过公司属性定义.
 */
public class GlobalConfigKeys {

    /**
     * 默认公司logo跟踪.
     */
    public final static String CORP_DEFAULT_LOGO_URL = "corp.default.logo";


    // 自定义扩展web资源.
    public final static String WEB_ASSET_BASE = "web.asset.base";  // sample: //a.cdn6.cn/web-react
    public final static String WEB_CUSTOM_ASSETS = "web.custom.assets";

    /**
     * Exchange 配置
     */
    public static String EWS_URL          = "exchange.ws.url";
    public static String EWS_USERNAME     = "exchange.ws.username";
    public static String EWS_DOMAIN       = "exchange.ws.domain";
    public static String EWS_PASSWORD     = "exchange.ws.password";
    public static String EWS_MAIL_POSTFIX = "exchange.ws.mail_postfix";
    public static String EWS_MOCK_OWNER = "exchange.ws.mock_owner";

    /**
     * 自定义登录和注销地址
     */
    public final static String CUSTOM_LOGIN_URL  = "custom.login.url";
    public final static String CUSTOM_LOGOUT_URL = "custom.logout.url";

    /**
     * 当签到后，门禁是否保持常开.
     * 默认保持常开.
     */
    public static final String DOOR_ALWAY_OPEN_AFTER_CHECKIN = "door.alway.open.after.checkin";

    /**
     * 员工信息必须精确输入才能match.
     */
    public static final String EXACT_MATCH_USER = "query.exact.match.user";

    /**
     * LDAP 同步配置.
     */
    public static String LDAP_DOMAIN   = "ldap.domain";
    public static String LDAP_HOST     = "ldap.host";
    public static String LDAP_PORT     = "ldap.port";
    public static String LDAP_USERNAME = "ldap.username";
    public static String LDAP_PASSWORD = "ldap.password";

    public static String LDAP_BASE_NAME         = "ldap.base.name";
    public static String LDAP_IGNORE_PATHS      = "ldap.ignore.paths";
    public static String LDAP_OBJECT_CLASS      = "ldap.object_class";
    public static String LDAP_DEPT_OBJECT_CLASS = "ldap.dept.object_class";
    public static String LDAP_USER_OBJECT_CLASS = "ldap.user.object_class";

    // LDAP 组名，如果设置过，则使用此属性作为部门.
    public static String LDAP_GROUP_OBJECT_CLASS = "ldap.group.object_class";

    public static String LDAP_USER_COL_NAME = "ldap.user.col.name";
    public static String LDAP_USER_COL_LOGIN = "ldap.user.col.login";
    public static String LDAP_USER_COL_EMAIL = "ldap.user.col.mail";
    public static String LDAP_USER_COL_MOBILE = "ldap.user.col.mobile";
    public static String LDAP_USER_COL_TEL = "ldap.user.col.tel";
    public static String LDAP_USER_COL_DISTINGUISHED_NAME = "ldap.user.col.distinguishedName";

    public static String LDAP_DEPT_COL_NAME = "ldap.dept.col.name";
    public static String LDAP_DEPT_COL_DESCRIPTION = "ldap.dept.col.description";
    public static String LDAP_DEPT_COL_DISTINGUISHED_NAME = "ldap.dept.col.distinguishedName";

    /**
     * 平板App
     */
    public final static String TABLET_APP_VERSION = "tablet.app.version";   // 平板显示App Version
    public final static String TABLET_APP_URL     = "tablet.app.url";         // 平板显示App下载URL

    /**
     * 动态字段，用于...?
     */
    private final static List<String> dynaFieldList = Arrays.asList(
            "workflow.car.default",
            "workflow.room.default"
    );

    /**
     * 可用的配置字段列表
     */
    private static Set<String> staticFieldSet = null;

    public static Set<String> getStaticFieldSet() {
        if (staticFieldSet == null) {
            staticFieldSet = new HashSet<>();

            Field[] declaredFields = GlobalConfigKeys.class.getDeclaredFields();
            for (Field field : declaredFields) {
                if (java.lang.reflect.Modifier.isStatic(field.getModifiers())
                        && field.getType() == String.class
                        ) {

                    Logger.info("LOG05223: GlobalConfigKeys static field: %s, class:%s, type:%s",
                            field.getName(), field.getDeclaringClass(), field.getType());
                    try {
                        staticFieldSet.add(String.valueOf(field.get(null)));
                    } catch (IllegalAccessException e) {
                        // donothing
                    }
                }
            }
            staticFieldSet.addAll(dynaFieldList);
        }

        return staticFieldSet;
    }
}
